﻿USE [ORM_SmackDown]
GO
/****** Object:  Table [dbo].[Roles]    Script Date: 08/26/2009 16:23:56 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Roles](
	[RoleId] [int] IDENTITY(1,1) NOT NULL,
	[RoleName] [varchar](50) NOT NULL,
	[IsForPortal] [bit] NOT NULL,
	[IsForContact] [bit] NOT NULL,
 CONSTRAINT [PK_Roles] PRIMARY KEY CLUSTERED 
(
	[RoleId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Companies]    Script Date: 08/26/2009 16:23:56 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Companies](
	[CompanyId] [int] IDENTITY(1,1) NOT NULL,
	[CompanyName] [varchar](50) NOT NULL,
 CONSTRAINT [PK_Contact] PRIMARY KEY CLUSTERED 
(
	[CompanyId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Performance]    Script Date: 08/26/2009 16:23:56 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Performance](
	[PerformanceId] [int] IDENTITY(1,1) NOT NULL,
	[OrmName] [varchar](128) NOT NULL,
	[Action] [varchar](128) NOT NULL,
	[MilliSeconds] [int] NOT NULL,
 CONSTRAINT [PK_Performance] PRIMARY KEY CLUSTERED 
(
	[PerformanceId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[People]    Script Date: 08/26/2009 16:23:56 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[People](
	[PersonId] [int] IDENTITY(1,1) NOT NULL,
	[FirstName] [varchar](50) NOT NULL,
	[LastName] [varchar](50) NOT NULL,
	[Email] [varchar](128) NOT NULL,
	[CompanyId] [int] NULL,
	[RoleId] [int] NULL,
	[ManagerPersonId] [int] NULL,
	[UserType] [char](2) NOT NULL,
 CONSTRAINT [PK_Users] PRIMARY KEY CLUSTERED 
(
	[PersonId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Messages]    Script Date: 08/26/2009 16:23:56 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Messages](
	[MessageId] [int] IDENTITY(1,1) NOT NULL,
	[SenderUserId] [int] NOT NULL,
	[Subject] [varchar](255) NOT NULL,
	[Body] [text] NOT NULL,
 CONSTRAINT [PK_Messages] PRIMARY KEY CLUSTERED 
(
	[MessageId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Portals]    Script Date: 08/26/2009 16:23:56 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Portals](
	[PortalId] [int] IDENTITY(1,1) NOT NULL,
	[PortalName] [varchar](50) NOT NULL,
	[AdminUserId] [int] NOT NULL,
 CONSTRAINT [PK_Portals] PRIMARY KEY CLUSTERED 
(
	[PortalId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Addresses]    Script Date: 08/26/2009 16:23:56 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Addresses](
	[AddressId] [int] IDENTITY(1,1) NOT NULL,
	[PersonId] [int] NOT NULL,
	[IsDefault] [bit] NOT NULL,
	[Line1] [varchar](128) NOT NULL,
	[Line2] [varchar](128) NULL,
	[City] [varchar](128) NOT NULL,
	[State] [varchar](2) NOT NULL,
	[ZipCode] [char](5) NOT NULL,
	[ZipCodePlusFour] [char](4) NOT NULL,
 CONSTRAINT [PK_Addresses] PRIMARY KEY CLUSTERED 
(
	[AddressId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[Recipients]    Script Date: 08/26/2009 16:23:56 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Recipients](
	[RecipientId] [int] NOT NULL,
	[UserId] [int] NOT NULL,
	[MessageId] [int] NOT NULL,
 CONSTRAINT [PK_Recipients] PRIMARY KEY CLUSTERED 
(
	[RecipientId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[PortalPeopleXref_LS]    Script Date: 08/26/2009 16:23:56 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PortalPeopleXref_LS](
	[PortalPeopleXrefId] [int] IDENTITY(1,1) NOT NULL,
	[PortalId] [int] NOT NULL,
	[PersonId] [int] NOT NULL,
 CONSTRAINT [PK_PortalPeopleXref_LS] PRIMARY KEY CLUSTERED 
(
	[PortalPeopleXrefId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[PortalPeopleXref]    Script Date: 08/26/2009 16:23:56 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PortalPeopleXref](
	[PortalId] [int] NOT NULL,
	[PersonId] [int] NOT NULL,
 CONSTRAINT [PK_PortalPeopleXref_1] PRIMARY KEY CLUSTERED 
(
	[PortalId] ASC,
	[PersonId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Default [DF_Roles_IsForPortal]    Script Date: 08/26/2009 16:23:56 ******/
ALTER TABLE [dbo].[Roles] ADD  CONSTRAINT [DF_Roles_IsForPortal]  DEFAULT ((1)) FOR [IsForPortal]
GO
/****** Object:  Default [DF_Roles_IsForContact]    Script Date: 08/26/2009 16:23:56 ******/
ALTER TABLE [dbo].[Roles] ADD  CONSTRAINT [DF_Roles_IsForContact]  DEFAULT ((1)) FOR [IsForContact]
GO
/****** Object:  ForeignKey [FK_Addresses_People]    Script Date: 08/26/2009 16:23:56 ******/
ALTER TABLE [dbo].[Addresses]  WITH CHECK ADD  CONSTRAINT [FK_Addresses_People] FOREIGN KEY([PersonId])
REFERENCES [dbo].[People] ([PersonId])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[Addresses] CHECK CONSTRAINT [FK_Addresses_People]
GO
/****** Object:  ForeignKey [FK_Messages_Users]    Script Date: 08/26/2009 16:23:56 ******/
ALTER TABLE [dbo].[Messages]  WITH CHECK ADD  CONSTRAINT [FK_Messages_Users] FOREIGN KEY([SenderUserId])
REFERENCES [dbo].[People] ([PersonId])
GO
ALTER TABLE [dbo].[Messages] CHECK CONSTRAINT [FK_Messages_Users]
GO
/****** Object:  ForeignKey [FK_People_Companies]    Script Date: 08/26/2009 16:23:56 ******/
ALTER TABLE [dbo].[People]  WITH CHECK ADD  CONSTRAINT [FK_People_Companies] FOREIGN KEY([CompanyId])
REFERENCES [dbo].[Companies] ([CompanyId])
GO
ALTER TABLE [dbo].[People] CHECK CONSTRAINT [FK_People_Companies]
GO
/****** Object:  ForeignKey [FK_People_Manager]    Script Date: 08/26/2009 16:23:56 ******/
ALTER TABLE [dbo].[People]  WITH CHECK ADD  CONSTRAINT [FK_People_Manager] FOREIGN KEY([ManagerPersonId])
REFERENCES [dbo].[People] ([PersonId])
GO
ALTER TABLE [dbo].[People] CHECK CONSTRAINT [FK_People_Manager]
GO
/****** Object:  ForeignKey [FK_People_Roles]    Script Date: 08/26/2009 16:23:56 ******/
ALTER TABLE [dbo].[People]  WITH CHECK ADD  CONSTRAINT [FK_People_Roles] FOREIGN KEY([RoleId])
REFERENCES [dbo].[Roles] ([RoleId])
GO
ALTER TABLE [dbo].[People] CHECK CONSTRAINT [FK_People_Roles]
GO
/****** Object:  ForeignKey [FK_PortalPeopleXref_People]    Script Date: 08/26/2009 16:23:56 ******/
ALTER TABLE [dbo].[PortalPeopleXref]  WITH CHECK ADD  CONSTRAINT [FK_PortalPeopleXref_People] FOREIGN KEY([PersonId])
REFERENCES [dbo].[People] ([PersonId])
GO
ALTER TABLE [dbo].[PortalPeopleXref] CHECK CONSTRAINT [FK_PortalPeopleXref_People]
GO
/****** Object:  ForeignKey [FK_PortalPeopleXref_Portals]    Script Date: 08/26/2009 16:23:56 ******/
ALTER TABLE [dbo].[PortalPeopleXref]  WITH CHECK ADD  CONSTRAINT [FK_PortalPeopleXref_Portals] FOREIGN KEY([PortalId])
REFERENCES [dbo].[Portals] ([PortalId])
GO
ALTER TABLE [dbo].[PortalPeopleXref] CHECK CONSTRAINT [FK_PortalPeopleXref_Portals]
GO
/****** Object:  ForeignKey [FK_PortalPeopleXref_LS_People]    Script Date: 08/26/2009 16:23:56 ******/
ALTER TABLE [dbo].[PortalPeopleXref_LS]  WITH CHECK ADD  CONSTRAINT [FK_PortalPeopleXref_LS_People] FOREIGN KEY([PersonId])
REFERENCES [dbo].[People] ([PersonId])
GO
ALTER TABLE [dbo].[PortalPeopleXref_LS] CHECK CONSTRAINT [FK_PortalPeopleXref_LS_People]
GO
/****** Object:  ForeignKey [FK_PortalPeopleXref_LS_Portals]    Script Date: 08/26/2009 16:23:56 ******/
ALTER TABLE [dbo].[PortalPeopleXref_LS]  WITH CHECK ADD  CONSTRAINT [FK_PortalPeopleXref_LS_Portals] FOREIGN KEY([PortalId])
REFERENCES [dbo].[Portals] ([PortalId])
GO
ALTER TABLE [dbo].[PortalPeopleXref_LS] CHECK CONSTRAINT [FK_PortalPeopleXref_LS_Portals]
GO
/****** Object:  ForeignKey [FK_Portals_Users]    Script Date: 08/26/2009 16:23:56 ******/
ALTER TABLE [dbo].[Portals]  WITH CHECK ADD  CONSTRAINT [FK_Portals_Users] FOREIGN KEY([AdminUserId])
REFERENCES [dbo].[People] ([PersonId])
GO
ALTER TABLE [dbo].[Portals] CHECK CONSTRAINT [FK_Portals_Users]
GO
/****** Object:  ForeignKey [FK_Recipients_Messages]    Script Date: 08/26/2009 16:23:56 ******/
ALTER TABLE [dbo].[Recipients]  WITH CHECK ADD  CONSTRAINT [FK_Recipients_Messages] FOREIGN KEY([MessageId])
REFERENCES [dbo].[Messages] ([MessageId])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[Recipients] CHECK CONSTRAINT [FK_Recipients_Messages]
GO
/****** Object:  ForeignKey [FK_Recipients_Users]    Script Date: 08/26/2009 16:23:56 ******/
ALTER TABLE [dbo].[Recipients]  WITH CHECK ADD  CONSTRAINT [FK_Recipients_Users] FOREIGN KEY([UserId])
REFERENCES [dbo].[People] ([PersonId])
GO
ALTER TABLE [dbo].[Recipients] CHECK CONSTRAINT [FK_Recipients_Users]
GO
